package net.zjitc;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/9/27.
 */
@WebServlet(name = "CountServlet",urlPatterns = "/CountServlet")
public class CountServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context=this.getServletContext();
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();

        Integer count;
        count= (Integer) context.getAttribute("count");
        count++;
        if(count==null)
        {
            out.write("这是你第"+count+"次访问");
        }else
        {
            out.write("这是你第"+count+"次访问");
        }
        context.setAttribute("count",count);

    }
    }

